********************************************************************************
*Project:  	Swiss Trade During the Covid-19 Pandemic: An Early Appraisal	
*Authors:	KB, SL, VP, PW												
*This File: Figure 1
*Version: 	vFinal						
*Date: 		2020-09-01				
********************************************************************************

********************************************************************************
*1. Cases in Selected Countries
********************************************************************************


* I. Import and Prepare Data 

// Download from https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series
// or https://ourworldindata.org/grapher/covid-daily-vs-total-cases-per-million
	

import delimited ${root}\data\COVID_DATA\covid-daily-vs-total-cases-per-million_v20200828.csv, ///
delimiter(comma) bindquote(nobind) stripquote(yes) clear 

rename code countrycode_iso3
rename dailyconfirmedcasespermillion year
rename totalconfirmedcasespermillioncas  daily_per_mil
rename v6 total_per_mil

replace daily_per_mil = 0 if daily_per_mil == .
replace total_per_mil = 0 if total_per_mil == .

split date, parse(" ")
rename date1 month
rename date2 day

drop if month=="Dec"

replace month="1" if month=="Jan"
replace month="2" if month=="Feb"
replace month="3" if month=="Mar"
replace month="4" if month=="Apr"
replace month="5" if month=="May"
replace month="6" if month=="Jun"
replace month="7" if month=="Jul"
replace month="8" if month=="Aug"

destring year, replace
destring month, replace
destring day, replace
drop date

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

gen monday = date - cond(dow(date) == 0, 6, dow(date) - 1)
format monday %tddd.nn.YY

sort entity year month day
bysort entity monday: gen count=_n

gen keep =0
replace keep=1 if month==1 & day==5 & year==2020
replace keep=1 if count==7
drop if keep==0

gen total_per_1000=total_per_mil/1000

twoway 	///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Germany", lcolor(gs12*0.5) lwidth(medthin)) 	///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="France", lcolor(gs12*0.5) lwidth(medthin))		///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Italy", lcolor(gs12*0.5) lwidth(medthin))		///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Austria", lcolor(gs12*0.5) lwidth(medthin))		///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Netherlands", lcolor(gs12*0.5) lwidth(medthin))		///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Japan", lpattern(shortdash) lcolor(gs8) lwidth(medium))		///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="China", lpattern(dash) lcolor(gs6) lwidth(medium)) 	///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="United Kingdom", lpattern(longdash) lcolor(gs2) lwidth(medium))	///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Spain", lpattern(dash_dot) lcolor(gs10) lwidth(medthin))		///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="United States", lpattern(shortdash) lcolor(black) lwidth(medthin)) ///
(line total_per_1000 date if date>=td(1jan2020) & date<=td(3aug2020) & entity=="Switzerland", lcolor(maroon) lwidth(medium)),	///
ytitle("Total Cases per Thousand People")  yscale(range(-1 15))  ///
 xlabel(#8)  xtitle("")									///
tline(16mar2020, lcolor(maroon) lwidth(medium)) 								///
ttext(-1 15mar2020 "Swiss Lockdown (16.3.2020)", place(e) size(small) orient(horizontal) color(maroon))  ///
legend(order (6 "Japan" 7 "China" 10 "United States" 8 "United Kingdom"  11 "Switzerland" 9 "Spain") cols(3))			///
scheme(s1color) 
graph export "${root}\figures\FIG1a_covid19_TotalperTHD_2020.png", replace
graph export "${root}\figures\FIG1b_covid19_TotalperTHD_2020.pdf", replace


********************************************************************************
*2. Government Stringency in Selected Countries
********************************************************************************

* I. Import Data 

// (i) Download from https://www.bsg.ox.ac.uk/research/research-projects/coronavirus-government-response-tracker#data
// (ii) Save Gov Index Sheet, transposed as "OxCGRT_timeseries_all_edited.xlsx"
	
import delimited "${root}\data\COVID_DATA\OxCGRT_v20200828.txt", 	///
delimiter(comma) bindquote(nobind) stripquote(yes) clear 


tostring date, replace
gen year=substr(date, 1,4)
gen month=substr(date, 5,2)
gen day=substr(date, 7,2)

destring year, replace
destring month, replace
destring day, replace
drop date

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

gen monday = date - cond(dow(date) == 0, 6, dow(date) - 1)
format monday %tddd.nn.YY

sort countryname monday date

keep countryname countrycode stringencyindex governmentresponseindex year month day date monday

collapse (mean) stringencyindex governmentresponseindex, by(countryname countrycode monday)

rename monday date_mo
rename stringencyindex stringency_index

* II. Create Plot
twoway 	///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Germany", lcolor(gs12*0.5) lwidth(medthin)) 	///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="France", lcolor(gs12*0.5) lwidth(medthin))		///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Italy", lcolor(gs12*0.5) lwidth(medthin))		///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Austria", lcolor(gs12*0.5) lwidth(medthin))		///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Spain", lcolor(gs12*0.5) lwidth(medthin))		///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="United States", lcolor(gs12*0.5) lwidth(medthin)) ///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Netherlands", lcolor(gs12*0.5) lwidth(medthin))		///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Japan", lpattern(shortdash) lcolor(gs8) lwidth(medium))		///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="China", lpattern(dash) lcolor(gs6) lwidth(medium)) 	///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="United Kingdom", lpattern(longdash) lcolor(gs2) lwidth(medium))	///
(line stringency_index date if date>=td(1jan2020) & date<=td(3aug2020) & countryname=="Switzerland", lcolor(maroon) lwidth(medium)),	///
ytitle("Government Stringency Index")  yscale(range (0 100))  ///
ylabel(0(20)100,nogrid) xlabel(#8)  xtitle("")									///
tline(16mar2020, lcolor(maroon) lwidth(medium)) 								///
ttext(1 15mar2020 "Swiss Lockdown (16.3.2020)", place(e) size(small) orient(horizontal) color(maroon))  ///
legend(order (8 "Japan" 9 "China" 10 "United Kingdom" 11 "Switzerland") cols(2))			///
scheme(s1color) 
graph export "${root}\figures\FIG1b_gov_string_2020.png", replace
graph export "${root}\figures\FIG1b_gov_string_2020.pdf", replace
